package com.hzcx.app.simplechat.model;

import android.content.Context;

import com.hzcx.app.simplechat.api.APIRequest;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.api.RxHelper;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendCityBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendLableInfoBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendLableListBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendRequestBean;
import com.hzcx.app.simplechat.ui.main.bean.FriendRequestCountBean;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.util.List;

/**
 * 好友相关
 */
public class FriendModel {


    /**
     * 删除好友
     *
     * @param context
     * @param id
     * @param observer
     */
    public static void deleteFriend(Context context, int id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .deleteFriend(TokenUtils.getTokenHeader(), id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取好友列表
     *
     * @param context
     * @param observer
     */
    public static void getFriendList(Context context, BaseObserver<List<FriendBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getFriendList(TokenUtils.getTokenHeader())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /**
     * 获取好友请求列表
     *
     * @param context
     * @param observer
     */
    public static void getFriendRequestList(Context context, BaseObserver<List<FriendRequestBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getFriendRequestList(TokenUtils.getTokenHeader())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 发送加好友请求
     *
     * @param context
     * @param member_id
     * @param ver_request
     * @param observer
     */
    public static void sendAddFriendRequest(Context context, int member_id, String ver_request, int type, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .sendAddFriendRequest(TokenUtils.getTokenHeader(), member_id, ver_request, type)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 同意好友请求
     *
     * @param context
     * @param id
     * @param observer
     */
    public static void agreeFriendRequest(Context context, int id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .agreeFriendRequest(TokenUtils.getTokenHeader(), id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取好友请求新消息条数
     *
     * @param context
     * @param observer
     */
    public static void getFriendRequestCount(Context context, BaseObserver<FriendRequestCountBean> observer) {
        APIRequest
                .getRequestInterface()
                .getFriendRequestCount(TokenUtils.getTokenHeader())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 搜索好友
     *
     * @param context
     * @param serch_keys
     * @param observer
     */
    public static void searchFriend(Context context, String serch_keys, BaseObserver<List<FriendCityBean>> observer) {
        APIRequest
                .getRequestInterface()
                .searchFriend(TokenUtils.getTokenHeader(), serch_keys)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 创建标签
     *
     * @param context
     * @param member_ids
     * @param name
     * @param lable_id
     * @param observer
     */
    public static void createFriendLable(Context context, String member_ids, String name, String lable_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .createFriendLable(TokenUtils.getTokenHeader(), member_ids, name, lable_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取标签列表
     *
     * @param context
     * @param observer
     */
    public static void getFriendLableList(Context context, BaseObserver<List<FriendLableListBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getFriendLableList(TokenUtils.getTokenHeader())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 删除标签
     *
     * @param context
     * @param lable_id
     * @param observer
     */
    public static void deleteFriendLable(Context context, int lable_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .deleteFriendLable(TokenUtils.getTokenHeader(), lable_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 获取标签详情
     *
     * @param context
     * @param lable_id
     * @param observer
     */
    public static void getFriendLableInfo(Context context, String lable_id, BaseObserver<FriendLableInfoBean> observer) {
        APIRequest
                .getRequestInterface()
                .getFriendLableInfo(TokenUtils.getTokenHeader(), lable_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /**
     * 排序好友或获取好友列表
     *
     * @param context
     * @param serch_keys
     * @param sort_type
     * @param observer
     */
    public static void getFriendBySort(Context context, String serch_keys, String sort_type, BaseObserver<List<FriendCityBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getFriendBySort(TokenUtils.getTokenHeader(), serch_keys, sort_type)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }
}
